//
//  PictureCell.m
//  ProjectsOne
//
//  Created by iOS开发 on 2018/7/9.
//  Copyright © 2018年 iOS开发. All rights reserved.
//

#import "PictureCell.h"

@interface PictureCell ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *sourceLabel;
@property (nonatomic, strong) UIImageView *picImageView;
@end

@implementation PictureCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = [UIColor colorWithHexString:@"c5c5c5"];
    [self addSubview:line];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).with.offset(15);
        make.right.mas_equalTo(self).with.offset(-15);
        make.bottom.mas_equalTo(self);
        make.height.mas_equalTo(.5f);
    }];
    
    _sourceLabel = [[UILabel alloc] init];
    _sourceLabel.font = [UIFont systemFontOfSize:14];
    _sourceLabel.textAlignment = NSTextAlignmentLeft;
    _sourceLabel.textColor = [UIColor colorWithHexString:@"#999999"];
    [self addSubview:_sourceLabel];
    
    [_sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).with.offset(15);
        make.baseline.mas_equalTo(self).with.offset(-18);
        make.width.mas_equalTo(WIDTH / 2);
    }];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.numberOfLines = 2;
    _titleLabel.font = [UIFont systemFontOfSize:19];
    _titleLabel.textColor = [UIColor colorWithHexString:@"333333"];
    [self addSubview:_titleLabel];

    _picImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic"]];
    _picImageView.layer.cornerRadius = 3;
    _picImageView.layer.shouldRasterize = YES;
    _picImageView.backgroundColor = [UIColor redColor];
    [self addSubview:_picImageView];
    
    [_picImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).with.offset(-15);
        make.top.mas_equalTo(self).with.offset(14);
        make.bottom.mas_equalTo(self).with.offset(-14);
        make.width.mas_equalTo(115);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).with.offset(15);
        make.right.mas_equalTo(self.picImageView.mas_left).with.offset(-22);
        make.top.mas_equalTo(self).with.offset(15);
        make.bottom.mas_equalTo(self.sourceLabel).with.offset(-20);
    }];
}

- (void)setModel:(NewsModel *)model {
    _sourceLabel.text = [NSString stringWithFormat:@"%@", model.source];
    _titleLabel.text = [NSString stringWithFormat:@"%@", model.title];
}

@end
